package UIComponents.FriendGive
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.filters.BitmapFilterQuality;
	import flash.filters.GlowFilter;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.utils.getDefinitionByName;
	
	public class GiveItem extends Sprite
	{
		public var itemName:String;
		public var lock:Boolean;
		public var isask:Boolean;
		public var picName:String;
		public var hotPanel:Sprite;
		public var type:String;
		public function GiveItem()
		{
			hotPanel	=	( new ( getDefinitionByName("hotPanel") as Class)) as Sprite;
			this.addChild( hotPanel);
			this.hotPanel.visible	=	false;
			hotPanel.x	=	0;//this.x;
			hotPanel.y	=	-	this.hotPanel.height;
			hotPanel.mouseEnabled	=	hotPanel.mouseChildren			=	false;
			(hotPanel.getChildByName("txt") as TextField).autoSize		=	TextFieldAutoSize.CENTER;
			(hotPanel.getChildByName("txt") as TextField).wordWrap		=	true;
			(this.getChildByName("lb") as Sprite).visible				=	false;
			
			this.addEventListener(MouseEvent.ROLL_OVER, function(e:Event){
				hotPanel.visible	=	true;
			});
			this.addEventListener(MouseEvent.ROLL_OUT, function(e:Event){
				hotPanel.visible	=	false;
			});
			
			this.addEventListener(MouseEvent.CLICK, onclick);
		}
		
		public function onclick(e:Event):void
		{
			if(this.lock)return;
			
			if( FriendGive.instance.selectItem){
				FriendGive.instance.selectItem.setGlowFilter(false);
				FriendGive.instance.selectItem.reshow();
			}
			this.setGlowFilter(true);
			FriendGive.instance.selectItem	=	this;
			
		}
		
		public function setData(obj:Object):void
		{
			itemName	=	obj.itemName;
			lock		=	obj.lock;
			isask		=	obj.isask;
			picName		=	obj.picName;	
			type		=	obj.type;
			
			(hotPanel.getChildByName("txt") as TextField).text		=	itemName;
			(this.getChildByName("lb") as Sprite).visible			=	true;
		}
		
		public function reshow():void
		{
			clean();
			
			if(lock)
			{
				(this.getChildByName("lock") as Sprite).visible=true;
				this.filters	=	FriendGive.instance.filterslblock;
				this.buttonMode	=	false;
			}
			
			if(isask)
			{
				(this.getChildByName("askSign") as Sprite).visible	=	true;	
				(this.getChildByName("askSign") as Sprite).filters	=	FriendGive.instance.filtersMzlbAsk2;
			}
			
//			trace( picName, ( new getDefinitionByName(picName) as Class));
			var pic:Sprite	= ( new ( getDefinitionByName(picName) as Class)) as Sprite;
			(this.getChildByName("pic") as Sprite).addChild( pic);
		}
		
		public function clean():void
		{
			while( (this.getChildByName("pic") as Sprite).numChildren)
				(this.getChildByName("pic") as Sprite).removeChildAt(0);
			
			(this.getChildByName("lock") as Sprite).visible=false;
			(this.getChildByName("askSign") as Sprite).visible=false;
			
			this.filters	=	null;
			(this.getChildByName("lb") as Sprite).filters	=	null;
			(this.getChildByName("askSign") as Sprite).filters	=	null;
			this.buttonMode	= true;
		}
		
		/**
		 *设定发光效果 
		 * @param value
		 * 
		 */		
		public function setGlowFilter(value:Boolean):void
		{
			//			
			if(value)
			{
				var filter:GlowFilter=new GlowFilter(0xffffff,0.8,20,20,2,BitmapFilterQuality.LOW);
				var filters:Array=[filter];
				this.filters=filters;
			}
			else
			{
				this.filters=null;
			}
		}
	}
}